using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace Pong_Xvna
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Sprite : Microsoft.Xna.Framework.DrawableGameComponent
    {
        protected Texture2D[] texture;
        protected int nTexture2D;
        protected int iTexture2D;
        protected Vector2 position, velocity;
        protected SpriteBatch sp;
        private Microsoft.Xna.Framework.Game game1;

        public Microsoft.Xna.Framework.Game Game1
        {
            get { return game1; }
            set { game1 = value; }
        }
        public SpriteVelocityState svs;
        public Vector2 Center
        {
            get { return position + new Vector2(texture[iTexture2D].Width / 2, texture[iTexture2D].Height / 2); }
        }
        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }
        public Vector2 Velocity
        {
            get { return velocity; }
            set { velocity = value; }
        }
        public void VelocityX()
        {
            if (this.velocity.X >= 0)
            {
                this.velocity.X = svs.VelocityState();
                this.position.X = this.position.X - 5;
            }
            else
            {
                this.velocity.X = -svs.VelocityState();
                this.position.X = this.position.X + 5;
            }
            iTexture2D = svs.ImgState();
        }
        public Sprite(Game game,Vector2 pos, Vector2 velo)
            : base(game)
        {
            
            this.position = pos;
            this.velocity = velo;

            sp = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));

            Game.Components.Add(this);
        }

       
        public override void Initialize()
        {           
            base.Initialize();
        }

        public Rectangle getBound()
        {
            return new Rectangle((int)position.X, (int)position.Y, texture[iTexture2D].Width, texture[iTexture2D].Height);
        }
        public bool CheckCollides(Sprite s)
        {
            return getBound().Intersects(s.getBound());
        }
        public override void Update(GameTime gameTime)
        {
           position  += velocity;
            base.Update(gameTime);
        }
        public override void Draw(GameTime gameTime)
        {
            sp.Draw(texture[iTexture2D], position, Color.White);
            base.Draw(gameTime);
        }
        public virtual Sprite Clone()
        {
            return null;
        }
        
    }
}